package cn.wolfcode.education.service.impl;

import cn.wolfcode.education.domain.School;
import cn.wolfcode.education.domain.SchoolLinkman;
import cn.wolfcode.education.mapper.SchoolLinkmanMapper;
import cn.wolfcode.education.query.QueryObject;
import cn.wolfcode.education.service.ISchoolLinkmanService;
import cn.wolfcode.education.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SchoolLinkmanServiceImpl implements ISchoolLinkmanService {
    @Autowired
    private SchoolLinkmanMapper schoolLinkmanMapper;

    public PageResult queryForList(QueryObject qo) {
        int count = schoolLinkmanMapper.queryForCount(qo);
        if (count == 0){
            return new PageResult();
        }
        List<School> list =  schoolLinkmanMapper.queryForList(qo);
        return new PageResult(count,list);
    }

    public void insert(SchoolLinkman schoolLinkman) {
        schoolLinkmanMapper.insert(schoolLinkman);
    }

    public void update(SchoolLinkman schoolLinkman) {
        schoolLinkmanMapper.updateByPrimaryKey(schoolLinkman);
    }
    //设置为主联系人
    public void setMainLinkman(Long id, Long schoolId) {
        //先设置其他的联系人的main为false;
        schoolLinkmanMapper.updateLinkmanMainFalseById(schoolId,false);
        schoolLinkmanMapper.updateLinkmanMain(id,true);
    }

    public List<SchoolLinkman> getLinkmanBySchoolId(Long schoolId) {
        return schoolLinkmanMapper.getLinkmanBySchoolId(schoolId);
    }
}
